package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.customview.DateViewDialog;

import java.util.Calendar;
import java.util.Locale;

public class AddPublicationOrderActivity1 extends Activity implements View.OnClickListener{
    private View rl_back;
    private TextView tv_title;
    private ImageView img_publication;
    private EditText edt__completion_date;
    private ImageView img_completion_date;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_add_publication_order1);

        init();
    }

    private void init(){
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        img_publication=findViewById(R.id.img_publication);
        edt__completion_date=findViewById(R.id.edt__completion_date);
        img_completion_date=findViewById(R.id.img_completion_date);

        tv_title.setText("广告上刊");
        rl_back.setOnClickListener(this);
        img_publication.setOnClickListener(this);
        img_completion_date.setOnClickListener(this);
    }

    private void showDateDialog() {
        DateViewDialog endDateChooseDialog = new DateViewDialog(this,
                new DateViewDialog.DateChooseInterface() {
                    @Override
                    public void getDateTime(String time, boolean longTimeChecked) {
                        edt__completion_date.setText(time);
                    }
                });
        endDateChooseDialog.setTimePickerGone(true);

        Calendar dateAndTime = Calendar.getInstance(Locale.getDefault());

        endDateChooseDialog.setDateDialogTitle(dateAndTime.get(Calendar.YEAR) + "-" + (dateAndTime.get(Calendar.MONTH) + 1) + "-" + dateAndTime.get(Calendar.DAY_OF_MONTH));
        endDateChooseDialog.showDateChooseDialog();

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            // 返回
            case R.id.rl_back:
                finish();
                break;
                // 编辑上刊信息
            case R.id.img_publication:
                startActivity(new Intent(AddPublicationOrderActivity1.this,EditPublicationActivity.class));
                break;
                // 完成日期
            case R.id.img_completion_date:
                showDateDialog();
                break;
        }
    }
}
